home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / lanutsrc.zip / WHOAMI.C < prev    next >
Text File  |  1992-07-14  |  2KB  |  83 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <dos.h>
  5.  
  6. #define DOS 0x21
  7. #define NETBIOS 0x5C
  8.  
  9. /* structure to allow easy access to both segment and offset portions of
  10.    far pointers */
  11. struct SEGOFFS {
  12.                  unsigned offs;
  13.                  unsigned seg;
  14.                 };
  15.  
  16. typedef union POINTER {
  17.             unsigned char far *ptr;
  18.             struct SEGOFFS l;
  19.             }POINTER;
  20.  
  21.  
  22. /* netbios_present ********************************************************************
  23.  Determine if a netbios has been loaded
  24. *****************************************************************************/
  25. int netbios_present() {
  26.   union REGS regs;
  27.   struct SREGS sregs;
  28.   unsigned char ncb[65];
  29.   POINTER ptr;
  30.   
  31.   
  32. /* make an NCB with an illegal NETBIOS command */
  33.   memset(ncb,0,65);
  34.   ncb[0] = 0x7F;
  35.   ptr.ptr = ncb;
  36.   
  37. /* try calling the illegal function */
  38.   regs.h.al = 0;
  39.   sregs.es =  ptr.l.seg;
  40.   regs.x.bx = ptr.l.offs;
  41.   int86x(NETBIOS,®s,®s,&sregs);
  42.   
  43. /* see if NETBIOS caught it and returned an error */
  44.   return(regs.h.al != 0);
  45. }
  46.  
  47. /* display machine name */
  48. int main(argc,argv) {
  49.   union REGS regs;
  50.   struct SREGS sregs;
  51.   char name[16];
  52.   POINTER ptr;
  53.  
  54.   if (!netbios_present()) {
  55.     puts("Netbios not loaded.");
  56.     return(1);
  57.   }
  58.   
  59.   ptr.ptr = name;
  60.   regs.x.ax=0x5E00;       /* get machine name function */
  61.   sregs.ds =  ptr.l.seg;
  62.   regs.x.dx = ptr.l.offs;  
  63.   
  64.   intdosx(®s,®s,&sregs);
  65.   
  66.   if (!regs.h.ch) {
  67.     puts("Your machine is nameless!");
  68.     return(2);
  69.   }
  70.   
  71.   
  72.  
  73.  
  74.   printf("Your machine is %s\n",name);
  75. }
  76.   
  77.   
  78.   
  79.  
  80.  
  81.  
  82.  
  83.